﻿using UnityEngine;

namespace Gj
{
    public class FollowLocationHelper : MonoBehaviour
    {
        public Vector2 offset;
        public Camera camera;
        public GameObject target;
        private bool _fixed;

        private void LateUpdate()
        {
            if (!_fixed) return;
            var p = camera.WorldToScreenPoint(target.transform.position);
            transform.position = new Vector3(p.x + offset.x * SystemInput.scale, p.y + offset.y * SystemInput.scale, 0);
        }

        private void OnEnable()
        {
            _fixed = true;
        }

        private void OnDisable()
        {
            _fixed = false;
        }
    }
}